$(function(){
	showclass(null);
	$("#class-seek").click(function(){
		showclass($("#seekinfo").val());
	})
})
function showclass(seek){
	$.ajax({
		url:"/blackhouse/seeclass",
		data:{"seek":seek},
		type:"post",
		dataType:"json",
		success : function(e) {
			var html = "";
			for(var i = 0;i<e.length;i++){
				html += "<tr>";
				html += "<td>" + e[i].gradename + "</td>";
				html += "<td>" + e[i].classCode + "</td>";
				html += "<td class='f'><input type='text' value='"+e[i].className+"'style='outline: none;border: none;'></td>";
				html += "<td>" + e[i].classMessage + "</td>";
				html += "<td>" + e[i].createTime + "</td>";
				html += "<td><a tag='"+e[i].id+"' onclick='changeinfo(this)'>保存</a>&nbsp;&nbsp;<a onclick='delclassinfo(this)' tag='"+e[i].id+"'>删除</a></td>";
				html += "</tr>"
			}
			$("#view-class-tbody").html(html);
		}
	})
}
function delclassinfo(e){
	var r=confirm("确认删除该班级信息吗");
	if (r==true)
	{
		var key=$(e).attr("tag");
		$.ajax({
	        url: "/blackhouse/seeclass",
	        type: "post",
	        data: { "key":key,"classname":null },
	        dataType: "json",
	        success: function(e) {
	        		if(e){
	        			swal("删除成功", "该班级已被删除", "success");
	        			showclass(null);
	        		}else{
	        			swal("删除失败", "后台异常", "error");
	        		}
	        	}
	        })
	}
	else
	{
		swal("取消成功", "请求取消", "error");
	}
	
}
function changeinfo(e){
	var key=$(e).attr("tag");
	var value = $(e).parent().parent().find(".f").find("input[type=text]").val();
	$.ajax({
        url: "/blackhouse/seeclass",
        type: "post",
        data: { "key":key,"classname":value },
        dataType: "json",
        success: function(e) {
        		if(e){
        			swal("保存成功", "该班级已改名", "success");
        			readyclass(null);
        		}else{
        			swal("保存失败", "后台异常", "error");
        		}
        	}
        })
}